class MainWindow(QMainWindow):
    def __init__(self, parent=None):

        self.spl = QGridLayout()
        
        self.frames_container = QWidget()
        self.frames_hbox = QHBoxLayout() 
        self.frames_hbox.setSizeConstraint(QLayout.SetMinAndMaxSize)
        self.frames_hbox.setSpacing(0)
        self.frames_container.setLayout(self.frames_hbox)

        self.sprite_frames_scrollarea = QScrollArea()
        self.sprite_frames_scrollarea.setWidget(self.frames_container)
        
        self.sprite_editor_container = QWidget()
        self.sprite_editor = SpriteEditor(self.frames_hbox, True)
        self.sprite_editor_vbox = QVBoxLayout()
        self.sprite_editor_hbox = QHBoxLayout()
        self.sprite_editor_hbox.addWidget(self.sprite_editor, Qt.AlignCenter)
        self.sprite_editor_vbox.addLayout(self.sprite_editor_hbox)
        self.sprite_editor_container.setLayout(self.sprite_editor_vbox)
        
        self.sprite_editor_group = QGroupBox("Sprite Editor")
        self.sprite_editor_scrollarea = QScrollArea()
        self.sprite_editor_scrollarea.setWidget(self.sprite_editor_container)
        self.sprite_editor_scrollarea.setAlignment(Qt.AlignCenter | Qt.AlignHCenter)
        self.sprite_editor_scrollarea.setMinimumSize(400,400)

        self.sprite_editor_scrollarea_vbox = QVBoxLayout()
        self.sprite_editor_scrollarea_vbox.addWidget(self.sprite_editor_scrollarea)
        self.sprite_editor_scrollarea_vbox.setSizeConstraint(QLayout.SetMinAndMaxSize)
        self.sprite_editor_group.setLayout(self.sprite_editor_scrollarea_vbox)

        self.spl.addWidget(self.sprite_editor_group, 0, 0, 1, 2)
        
        """Frames"""

        self.frames_buttonhbox_container = QWidget()
        self.frames_buttonhbox = QHBoxLayout(self.frames_buttonhbox_container)
        self.frames_addbutton = QPushButton("+")
        self.frames_delbutton = QPushButton("-")
        self.frames_buttonhbox.addWidget(self.frames_addbutton)
        self.frames_buttonhbox.addWidget(self.frames_delbutton)
        self.frames_buttonhbox.setAlignment(self.frames_addbutton, Qt.AlignLeft)
        self.frames_buttonhbox.setAlignment(self.frames_delbutton, Qt.AlignLeft)
        self.frames_buttonhbox.insertStretch(2)
        self.frames_buttonhbox.setContentsMargins(0,0,0,0)

        self.connect(self.frames_addbutton, SIGNAL("clicked()"), self.add_frame)
        self.connect(self.frames_delbutton, SIGNAL("clicked()"), self.delete_frame)
        
        self.frames_group = QGroupBox("Frames")
        self.frames_vbox = QVBoxLayout()
        self.frames_vbox.addWidget(self.sprite_frames_scrollarea)
        self.frames_vbox.addWidget(self.frames_buttonhbox_container)
        self.frames_group.setLayout(self.frames_vbox)
        
        self.preview_group = QGroupBox("Preview")
        self.preview_vbox = QVBoxLayout()
        self.preview = PreviewWindow(self.sprite_editor.sprite)
        self.preview_vbox.addWidget(self.preview)
        self.preview_group.setLayout(self.preview_vbox)

        self.spl.addWidget(self.frames_group, 1, 0, 1, 1)
        self.spl.addWidget(self.preview_group, 1, 1, 2, 1)
        
        self.sequencer_group = QGroupBox("Sequencer")
        self.sequencer_vbox = QVBoxLayout()
        #self.sequencer = PreviewWindow(sprite)
        #self.sequencer_vbox.addWidget(self.sequencer)
        self.sequencer_group.setLayout(self.sequencer_vbox)

        self.spl.addWidget(self.sequencer_group, 2, 0, 1, 1)

        """
        main_vbox = QVBoxLayout() 
        main_vbox.addLayout(self.spl)

        main_hbox = QHBoxLayout() 
        main_hbox.addLayout(main_vbox)
        """

        main_hbox_container = QWidget()

        """
        main_hbox_container.setLayout(main_hbox)
        """

        main_hbox_container.setLayout(self.spl)
        
        self.setCentralWidget(main_hbox_container)

